package kuzha.code.jvm;

import static kuzha.code.jvm.CodeGenUtils.emitIntValue;
import static org.objectweb.asm.Opcodes.AASTORE;
import static org.objectweb.asm.Opcodes.ACONST_NULL;
import static org.objectweb.asm.Opcodes.ANEWARRAY;
import static org.objectweb.asm.Opcodes.DUP;
import static org.objectweb.asm.Opcodes.PUTSTATIC;

import org.objectweb.asm.MethodVisitor;

class StringArrayPool extends AbstractPool<String[]> {
	public StringArrayPool(String fieldsPrefix, String systemName) {
		super(fieldsPrefix, systemName, "[Ljava/lang/String;");
	}
	
	protected void emitInitializeConstant(MethodVisitor mv, String fieldname, String[] obj) {
		emitIntValue(mv, obj.length);
		mv.visitTypeInsn(ANEWARRAY, "java/lang/String");
		for(int i = 0; i < obj.length; i++) {
			mv.visitInsn(DUP);
			emitIntValue(mv, i);
			if (obj[i] != null)
				mv.visitLdcInsn(obj[i]);
			else
				mv.visitInsn(ACONST_NULL);
			mv.visitInsn(AASTORE);
		}
		mv.visitFieldInsn(PUTSTATIC, systemName, fieldname, "[Ljava/lang/String;");
	}
}
